home *** CD-ROM | disk | FTP | other *** search
- /* moverel.c */
- /* Entered by A. Wayner */
-
- # include <graphics.h>
- # include <stdlib.h>
-
- main()
- {
- int graphdriver = DETECT;
- int graphmode, maxx, maxy, maxcolor;
- int xstep, ystep, stepsize, i, numsteps = 20;
-
- /* Detect adapter type and */
- /* initialize graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc");
- outtextxy( 10, 10, "Random motion with 'moveto' ");
-
- maxx = getmaxx() - 100;
- maxy = getmaxy() - 60;
- stepsize = maxy / numsteps;
- maxcolor = getmaxcolor();
- randomize(); /* Initialize random number generator */
-
- /* Exit when user presses a key */
- outtextxy( 10, getmaxy() - 30,"Press any key to exit : ");
- settextjustify( CENTER_TEXT, CENTER_TEXT );
-
- /* Set up initial position */
- moveto( maxx / 2 + 50, maxy / 2 + 30 );
-
- while( !kbhit())
- {
- for( i = 0; i < numsteps; i++ )
- {
- /* Generate random steps along */
- /* x and y directions */
- xstep = stepsize / 2 - random( stepsize );
- ystep = stepsize / 2 - random( stepsize );
- setcolor( LIGHTCYAN );
- moverel( xstep, ystep );
-
- outtext("x"); /* Draw an 'x' at the new point */
- }
- /* Move current point back to midpoint */
- /* of the screen */
- moveto( maxx / 2 + 50, maxy / 2 + 30 );
- }
-
- closegraph(); /* Exit graphics library */
-
- }